package safeCommitter.test.finder.simple;

import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;

import safeCommitter.model.adpters.ClassEntity;
import safeCommitter.model.adpters.ISCTest;
import safeCommitter.test.finder.core.ISCJavaFinder;
import safeCommitter.test.finder.core.ISCTestFinder;

public class SCSimpleTestFinder implements ISCTestFinder {

	private final ISCJavaFinder finder;
	private final Set<ClassEntity> clazzEntities;
	private Set<ISCTest> testsFound;

	public SCSimpleTestFinder(final IJavaProject javaProject,
			final Set<ClassEntity> clazzEntities) {
		finder = new SCJavaSimpleFinder(javaProject);
		this.clazzEntities = clazzEntities;
	}

	public Set<ISCTest> findTestsFromMethods(final IProgressMonitor monitor)
			throws CoreException {
		Set<ISCTest> returnSet = new HashSet<ISCTest>();
		returnSet.addAll(finder.findTestsFromMethods(clazzEntities, monitor));
		monitor.done();
		return returnSet;

	}

	public void run(final IProgressMonitor monitor)
			throws InvocationTargetException, InterruptedException {
		try {
			setTestsFound(findTestsFromMethods(monitor));
		} catch (CoreException e) {
			e.printStackTrace();
		}

	}

	public Set<ISCTest> getTestsFound() {
		return testsFound;
	}

	public void setTestsFound(final Set<ISCTest> testsFound) {
		this.testsFound = testsFound;
	}

	public Boolean getUserCancelled() {
		return finder.getUserCancelled();
	}
}
